<html>
<head><meta charset="utf-8"><title>No `FakeRead` emitted for `match` scrutinee? · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/No.20.60FakeRead.60.20emitted.20for.20.60match.60.20scrutinee.3F.html">No `FakeRead` emitted for `match` scrutinee?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="179900702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/No%20%60FakeRead%60%20emitted%20for%20%60match%60%20scrutinee%3F/near/179900702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/No.20.60FakeRead.60.20emitted.20for.20.60match.60.20scrutinee.3F.html#179900702">(Nov 05 2019 at 04:23)</a>:</h4>
<p>The MIR builder docs suggest that a <code>FakeRead</code> will always be emitted for the scrutinee of a <code>match</code> statement, but this seems <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018">not to be true in practice</a>. Is this expected behavior?</p>



<a name="179900811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/No%20%60FakeRead%60%20emitted%20for%20%60match%60%20scrutinee%3F/near/179900811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/No.20.60FakeRead.60.20emitted.20for.20.60match.60.20scrutinee.3F.html#179900811">(Nov 05 2019 at 04:26)</a>:</h4>
<p><code>qualify_consts.rs</code> uses the presence of a <code>FakeRead</code> to forbid <code>if</code> and <code>match</code> in consts (it also forbids basic blocks with multiple predecessors in the control-flow graph, which also catches <code>match</code> statements).</p>



<a name="179901007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/No%20%60FakeRead%60%20emitted%20for%20%60match%60%20scrutinee%3F/near/179901007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/No.20.60FakeRead.60.20emitted.20for.20.60match.60.20scrutinee.3F.html#179901007">(Nov 05 2019 at 04:31)</a>:</h4>
<p>I assumed that <code>FakeRead</code>s were getting stripped somewhere, but I was trying to modify the logic in <code>check_consts</code> and it appears as though they aren't present at all for some match statements. Specifically <a href="https://github.com/rust-lang/rust/blob/master/src/test/ui/consts/const-eval/match-test-ptr-null.rs" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/test/ui/consts/const-eval/match-test-ptr-null.rs">this one</a>.</p>



<a name="179901113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/No%20%60FakeRead%60%20emitted%20for%20%60match%60%20scrutinee%3F/near/179901113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/No.20.60FakeRead.60.20emitted.20for.20.60match.60.20scrutinee.3F.html#179901113">(Nov 05 2019 at 04:33)</a>:</h4>
<p>It would be best to not look for <code>FakeRead</code> at all and instead look only at <code>SwitchInt</code> when checking const bodies, but the span assigned to a <code>SwitchInt</code> terminator  for a <code>match</code> is weird: it points to the pattern for the first arm.</p>



<a name="179903647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/No%20%60FakeRead%60%20emitted%20for%20%60match%60%20scrutinee%3F/near/179903647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/No.20.60FakeRead.60.20emitted.20for.20.60match.60.20scrutinee.3F.html#179903647">(Nov 05 2019 at 05:48)</a>:</h4>
<p>Just ignore me. The weird span was causing me to miss the error from the fakeread</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>